// /////////////////////////////////////////////////////////////////////////////
//
// Name:            EntityComponent.cpp
// Author:          Michael Bartsch (ZCCdark203)
//
// Desc :           Abstraction base class for adding new functionalities to
//                  entities.
//
// License:         Copyright (C) 2009 Michael Bartsch and Contributors
//
//                  This program is free software: you can redistribute it
//                  and/or modify it under the terms of the zlib/libpng License.
//                  See main.cpp for conditions of distribution and use.
//
// /////////////////////////////////////////////////////////////////////////////

// Include files
#include "EntityComponent.h"


// EntityComponent class
// Static variables.
u32 EntityComponent::mIDCount = 0;

// EntityComponent constructor.
EntityComponent::EntityComponent(Entity *parent)
{
    // Get new unique ID.
    mID = mIDCount++;

    // Check if we got a valid pointer.
    if(parent != NULL)
    {
       if(parent->addComponent(this))
       {
          pParent = parent;
          parent->grab();
       }

       else pParent = NULL;
    }

    else pParent = NULL;
}

// EntityComponent deconstructor.
EntityComponent::~EntityComponent()
{
    if(pParent != NULL)
      pParent->drop();
}

// Gets the ID of the component.
u32 EntityComponent::getID() const
{
    return mID;
}

// Gets the name of the component.
const std::string& EntityComponent::getName() const
{
    return mName;
}

// Gets the parent of this component.
const Entity* EntityComponent::getParent()
{
    return pParent;
}

// Serializes this object.
bool EntityComponent::onSerialization(SerializedAttributes *attributes)
{
    return true;
}

// Deserializes this object.
bool EntityComponent::onDeserialization(SerializedAttributes *attributes)
{
    return true;
}

// End of File
